﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using The_Last_Knights.Event;
using The_Last_Knights.GUI;
using The_Last_Knights.GameScreen;
using The_Last_Knights.Helper;
using TabControl = The_Last_Knights.GUI.TabControl;

namespace GUIEvent
{
    public class BackgroundMenuEvent: EventEntity
    {        
        public override bool Execute(object source, object sender, string eventId, object wParam, object lParam)
        {
            NormalButton btn = source as NormalButton;
            if (eventId != "EVENT_GUI_BUTTON_CLICK")
                return true;
            if (btn == null)
                return false;
            switch (btn.Id)
            {
                case "Screen_Background_Menu_Container_Start":
                    MessageBox.Show("StartClicked");
                    break;
                case "Screen_Background_Menu_Container_Custom":
                    MessageBox.Show("CustomClicked");
                    break;
                case "Screen_Background_Menu_Container_Option":
                    ScreenManager.GetInstance().SwitchScreen("Screen_Option");
                    break;
                case "Screen_Background_Menu_Container_Credit":
                    ScreenManager.GetInstance().SwitchScreen("Credit_Screen");                    
                    break;
                case "Screen_Background_Menu_Container_Update":
                    MessageBox.Show("UpdateClicked");
                    break;
                case "Screen_Background_Menu_Container_Exit":
                    _Game.Exit();
                    break;
            }            
            return false;
        }

        public override void Update(GameTime gameTime)
        {            
        }
    }

    public class OptionMenuEvent: EventEntity
    {
        public override bool Execute(object source, object sender, string eventId, object wParam, object lParam)
        {
            NormalButton btn = source as NormalButton;
            if (eventId != "EVENT_GUI_BUTTON_CLICK")
                return true;
            if (btn == null)
                return false;
            switch (btn.Id)
            {
                case "Screen_Option_Menu_Container_OK":
                    ScreenManager.GetInstance().SwitchScreen("Screen_Background");
                    break;
                case "Screen_Option_Menu_Container_Cancel":
                    ScreenManager.GetInstance().SwitchScreen("Screen_Background");
                    break;
            }
            return false;
        }

        public override void Update(GameTime gameTime)
        {            
        }
    } 

    public class OptionTabControlEvent: EventEntity
    {
        int index;
        List<TabControl> _tabControls = new List<TabControl>()
                                            {
                                                GameEntityDictionary.GetValue("Screen_Option_Menu_Container_TabContainer_General") as TabControl,
                                                GameEntityDictionary.GetValue("Screen_Option_Menu_Container_TabContainer_KeyBinding") as TabControl,
                                                GameEntityDictionary.GetValue("Screen_Option_Menu_Container_TabContainer_Audio") as TabControl,
                                                GameEntityDictionary.GetValue("Screen_Option_Menu_Container_TabContainer_Video") as TabControl                                 
                                            };
        
        public override bool Execute(object source, object sender, string eventId, object wParam, object lParam)
        {           
            for (int i = 0; i < 4; i++)
            {
                if (_tabControls[i] == sender as TabControl)
                    index = i;
                _tabControls[i].IsFocus = false;
                _tabControls[i].Button.ChangeNormalState();
                _tabControls[i].Button.IsPushing = false;
            }
            _tabControls[index].IsFocus = true;
            _tabControls[index].Button.ChangePushState();
            _tabControls[index].Button.IsPushing = true;
            return true;
        }

        public override void Update(GameTime gameTime)
        {
            
        }
    }

    public class MasteryControlEvent: EventEntity
    {
        public override bool OnEvent(object source, object sender, string eventId, object wParam, object lParam)
        {
            NormalButton btn = source as NormalButton;
            NormalForm form = sender as NormalForm;

            if (btn != null) MessageBox.Show(btn.Id + "Hover");
            return true;
        }
    }
}
